package UseIO.Practice;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FIileCopyIncludeSon {
    public static void main(String[] args) throws IOException{
        // 文件夹的拷贝
        File file = new File("8.内置模块/UseFile");
        File dest = new File("8.内置模块/UseFileCopy");
        copyDirectory(file,dest);

    }

    public static void copyDirectory(File file,File dest) throws IOException {
        dest.mkdirs();
        File[] files = file.listFiles();
        for (File f : files) {
            if(f.isFile()){
                FileInputStream fis = new FileInputStream(f);
                FileOutputStream fos = new FileOutputStream(new File(dest,f.getName()));
                byte[] bytes = new byte[1024];
                int b;
                while ((b=fis.read())!= -1){
                    fos.write(bytes,0,b);
                }
            }else {
                copyDirectory(f,new File(dest,f.getName()));
            }
        }
    }

}
